
/** 
Copyright (c) 2010, Sheikh Abdul Wahid Ahmed
Details @ http://extremecodeworld.codeplex.com/license
**/

using System;
using System.Collections;
using System.Data;
using  MySql.Data.MySqlClient;
using System.Data.OracleClient; 

namespace EXtremecode.Common
{
	/// <summary>
	/// Summary description for TypeHash.
	/// </summary>
	public class FreeHash:Hashtable
	{
		private static FreeHash s_CSharpTypeHash;
		private static FreeHash s_SQLDBTypeHash;
		private static FreeHash s_MYSQLDBTypeHash;
		private static FreeHash s_TokenInfoHash;
		private static FreeHash s_UDType;
		private static FreeHash s_CSharpSystemTypeHash;
		private static FreeHash s_ControlPrefix;
		private static FreeHash s_OracleDBTypeHash;

		public FreeHash()
		{
		

			
		}
		public static FreeHash ControlPrefix
		{
			get
			{
				if(s_ControlPrefix == null)
				{
					FreeHash obj=new FreeHash();
					obj.Add("TextBox","txt");
					obj.Add("DropDownList","cmb");
					obj.Add("ASCXDatePicker","dtp");
					obj.Add("Label","lbl");
					obj.Add("ASCXTextBox","txt");
					obj.Add("ASCXCheckBox","chk");
					obj.Add("ASCXNumberBox","nmb");
					obj.Add("ASCXCombo","cmb");
					obj.Add("ASCXCheckBoxList","chkList");

					s_ControlPrefix=obj;
				}
				return s_ControlPrefix;
			}
		}	

		public static FreeHash CSharpType
		{
			get
			{
				if(s_CSharpTypeHash == null)
				{
					FreeHash obj=new FreeHash();
					

					obj.Add(Constants.UDTypes.TEXT,"string");
					obj.Add(Constants.UDTypes.INT,"int");
					obj.Add(Constants.UDTypes.DATE_TIME,"DateTime");
					obj.Add(Constants.UDTypes.DECIMAL,"decimal");
					obj.Add(Constants.UDTypes.SHORT,"short");
					obj.Add(Constants.UDTypes.BIT,"bool");
					obj.Add(Constants.UDTypes.BINARY,"byte[]");
					obj.Add(Constants.UDTypes.SHORT_BINARY,"byte[]");
					obj.Add(Constants.UDTypes.LONG,"long");
					obj.Add(Constants.UDTypes.DOUBLE,"double");
					obj.Add(Constants.UDTypes.BYTE,"byte");
					obj.Add(Constants.UDTypes.SINGLE,"float");

	
					s_CSharpTypeHash=obj;
				}
				return s_CSharpTypeHash;
			}
		}

		public static FreeHash CSharpSystemType
		{
			get
			{
				if(s_CSharpSystemTypeHash == null)
				{
					FreeHash obj=new FreeHash();
					

					obj.Add(Constants.UDTypes.TEXT,"String");
					obj.Add(Constants.UDTypes.INT,"Int32");
					obj.Add(Constants.UDTypes.DATE_TIME,"DateTime");
					obj.Add(Constants.UDTypes.DECIMAL,"Decimal");
					obj.Add(Constants.UDTypes.SHORT,"Int16");
					obj.Add(Constants.UDTypes.BIT,"Boolean");
					obj.Add(Constants.UDTypes.BINARY,"Byte[]");
					obj.Add(Constants.UDTypes.SHORT_BINARY,"Byte[]");
					obj.Add(Constants.UDTypes.LONG,"Int64");
					obj.Add(Constants.UDTypes.DOUBLE,"Double");
					obj.Add(Constants.UDTypes.BYTE,"Byte");
					obj.Add(Constants.UDTypes.SINGLE,"Single");
	
					s_CSharpSystemTypeHash=obj;
				}
				return s_CSharpSystemTypeHash;
			}
		}



		public static FreeHash UDType
		{
			get
			{
				if(s_UDType== null)
				{
					FreeHash obj=new FreeHash();
					

					obj.Add("String",Constants.UDTypes.TEXT);
					obj.Add("string",Constants.UDTypes.TEXT);

					obj.Add("Int32",Constants.UDTypes.INT);
					obj.Add("int",Constants.UDTypes.INT);

					obj.Add("DateTime",Constants.UDTypes.DATE_TIME);
					
					obj.Add("Decimal",Constants.UDTypes.DECIMAL);
					obj.Add("decimal",Constants.UDTypes.DECIMAL);
					
					obj.Add("Int16",Constants.UDTypes.SHORT);
					obj.Add("short",Constants.UDTypes.SHORT);
					
					obj.Add("Byte[]",Constants.UDTypes.BINARY);
					
					obj.Add("Int64",Constants.UDTypes.LONG);
					obj.Add("long",Constants.UDTypes.LONG);
					
					obj.Add("Boolean",Constants.UDTypes.BIT);
					obj.Add("bool",Constants.UDTypes.BIT);

					obj.Add("Byte",Constants.UDTypes.BYTE);

					obj.Add("Double",Constants.UDTypes.DOUBLE);
					
					obj.Add("Single",Constants.UDTypes.SINGLE);
					obj.Add("float",Constants.UDTypes.SINGLE);



					s_UDType=obj;
				}
				return s_UDType;
			}
		}

		public static FreeHash TokenInfo
		{
			get
			{
				if(s_TokenInfoHash == null)
				{
					FreeHash obj=new FreeHash();
					

					obj.Add("TokenIdField","TokenId");
					obj.Add("TokenValueField","TokenValue");
					obj.Add("TokenTableName","Tokens");

					s_TokenInfoHash=obj;
				}
				return s_TokenInfoHash;
			}
		}

		public static FreeHash SQLDBType
		{
			get
			{
				if(s_SQLDBTypeHash == null)
				{
					FreeHash obj=new FreeHash();
					

					obj.Add(Constants.UDTypes.BINARY,((int)SqlDbType.Image).ToString());
					obj.Add(Constants.UDTypes.LONG,((int)SqlDbType.BigInt).ToString());
					obj.Add(Constants.UDTypes.TEXT,((int)SqlDbType.NVarChar).ToString());
					obj.Add(Constants.UDTypes.DATE_TIME,((int)SqlDbType.DateTime).ToString());
					obj.Add(Constants.UDTypes.SHORT_BINARY,((int)SqlDbType.VarBinary).ToString());
					obj.Add(Constants.UDTypes.BIT,((int)SqlDbType.Bit).ToString());
					obj.Add(Constants.UDTypes.INT,((int)SqlDbType.Int).ToString());
					obj.Add(Constants.UDTypes.DOUBLE,((int)SqlDbType.Float).ToString());
					obj.Add(Constants.UDTypes.BYTE,((int)SqlDbType.TinyInt).ToString());
					obj.Add(Constants.UDTypes.SHORT,((int)SqlDbType.SmallInt).ToString());
					obj.Add(Constants.UDTypes.DECIMAL,((int)SqlDbType.Decimal).ToString());
					obj.Add(Constants.UDTypes.SINGLE,((int)SqlDbType.Real).ToString());
					
					s_SQLDBTypeHash=obj;
				}
				return s_SQLDBTypeHash;
			}
		}


		public static FreeHash MYSQLDBType
		{
			get
			{
				if(s_MYSQLDBTypeHash == null)
				{
					FreeHash obj=new FreeHash();
					

					obj.Add(Constants.UDTypes.BINARY,((int)MySqlDbType.LongBlob).ToString());
					obj.Add(Constants.UDTypes.LONG,((int)MySqlDbType.Int64).ToString());
					obj.Add(Constants.UDTypes.TEXT,((int)MySqlDbType.LongText).ToString());
					obj.Add(Constants.UDTypes.DATE_TIME,((int)MySqlDbType.Datetime).ToString());
					obj.Add(Constants.UDTypes.SHORT_BINARY,((int)MySqlDbType.Binary).ToString());
					obj.Add(Constants.UDTypes.BIT,((int)MySqlDbType.Bit).ToString());
					obj.Add(Constants.UDTypes.INT,((int)MySqlDbType.Int32).ToString());
					obj.Add(Constants.UDTypes.DOUBLE,((int)MySqlDbType.Double).ToString());
					obj.Add(Constants.UDTypes.BYTE,((int)MySqlDbType.Byte).ToString());
					obj.Add(Constants.UDTypes.SHORT,((int)MySqlDbType.Int16).ToString());
					obj.Add(Constants.UDTypes.DECIMAL,((int)MySqlDbType.Decimal).ToString());
					obj.Add(Constants.UDTypes.SINGLE,((int)MySqlDbType.Float).ToString());
					
					s_MYSQLDBTypeHash=obj;
				}
				return s_MYSQLDBTypeHash;
			}
		}


		public static FreeHash OracleDBType
		{
			get
			{
				if(s_OracleDBTypeHash == null)
				{
					FreeHash obj=new FreeHash();
					

					obj.Add(Constants.UDTypes.BINARY,((int)OracleType.Blob).ToString());
					obj.Add(Constants.UDTypes.LONG,((int)OracleType.Number).ToString());
					obj.Add(Constants.UDTypes.TEXT,((int)OracleType.NVarChar).ToString());
					obj.Add(Constants.UDTypes.DATE_TIME,((int)OracleType.Timestamp).ToString());
					obj.Add(Constants.UDTypes.SHORT_BINARY,((int)OracleType.Blob).ToString());
					obj.Add(Constants.UDTypes.BIT,((int)OracleType.Number).ToString());
					obj.Add(Constants.UDTypes.INT,((int)OracleType.Int32).ToString());
					obj.Add(Constants.UDTypes.DOUBLE,((int)OracleType.Double).ToString());
					obj.Add(Constants.UDTypes.BYTE,((int)OracleType.Byte).ToString());
					obj.Add(Constants.UDTypes.SHORT,((int)OracleType.Int16).ToString());
					obj.Add(Constants.UDTypes.DECIMAL,((int)OracleType.Number).ToString());
					obj.Add(Constants.UDTypes.SINGLE,((int)OracleType.Float).ToString());
					
					s_OracleDBTypeHash=obj;
				}
				return s_OracleDBTypeHash;
			}
		}
		
		public string this[string key]
		{
			get
			{
				if(base.Contains(key))return (base[key] as string);
				return key;
			}
			
		}
		public  void Add(string key, string value)
		{
			if(base.Contains(key))throw new Exception(string.Format("[UE] Object with the key '{0}', already exsists",key));
			base.Add(key,value);
		}
		
		
		#region Hidden Methods
		public override void Add(object key, object value)
		{
			throw new Exception("[UE] method is not allowed");
		}
		public override void CopyTo(Array array, int arrayIndex)
		{
			throw new Exception("[UE] method is not allowed");

		}
		#endregion
	}
}
